package band.wukong.practice.javase.core.thread.sync;

/**
 * Desc: 释放对象的锁。子线程抛出异常终止，主线程仍然继续运行。
 * Author: sunjs
 * Date: 2009-11-6 16:47:19
 */
public class TestLock extends Thread {
    public static StringBuffer log = new StringBuffer();
    private int a = 1;

    public synchronized void print() {
        System.out.println("a = " + a);
    }

    public void run() {
        int ZERO = 0;
        synchronized (this) {
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                log.append(e.getMessage());
                throw new RuntimeException(e);
            }
            a = 1 / ZERO;
            a++;
        }
    }

    public static void main(String[] args) {
        TestLock machine = new TestLock();
        machine.start();
        Thread.yield();
        machine.print();
    }
}
